package org.example.service.impl;

import org.example.mapper.NotificationSubscriptionMapper;
import org.example.pojo.domain.NotificationSubscription;
import org.example.service.NotificationSubscriptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NotificationSubscriptionServiceImpl implements NotificationSubscriptionService {

    @Autowired
    private NotificationSubscriptionMapper subscriptionMapper;

    @Override
    public List<NotificationSubscription> getSubscriptionsByUser(Integer userId) {
        return subscriptionMapper.findByUserId(userId);
    }

    @Override
    public void subscribe(Integer userId, String notificationType) {
        NotificationSubscription subscription = new NotificationSubscription();
        subscription.setUserId(userId);
        subscription.setNotificationType(notificationType);
        subscriptionMapper.insertSubscription(subscription);
    }

    @Override
    public void unsubscribe(Integer subscriptionId) {
        subscriptionMapper.deleteSubscription(subscriptionId);
    }

    @Override
    public List<NotificationSubscription> getSubscriptionsByType(String notificationType) {
        return subscriptionMapper.findByNotificationType(notificationType);
    }
}
